package com.epfresh.supplier.adapter;

import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.epfresh.supplier.R;
import com.epfresh.supplier.entity.CustomerGroupItem;
import com.epfresh.supplier.widget.RecyclerViewAdapter;

import java.util.ArrayList;

/**
 * Created by zhuli on 2017/8/23.
 */

public class CustomermGroupAdapter extends RecyclerViewAdapter<CustomerGroupItem> {
    private String mAction;

    /**
     * 构造方法
     *
     * @param data 数据
     */
    public CustomermGroupAdapter(ArrayList<CustomerGroupItem> data) {
        super(data);
    }

    public void setAction(String action) {
        mAction = action;
    }

    @Override
    public RecyclerView.ViewHolder getViewHolder(View view) {
        return new CustomermGroupViewHolder(view, false);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType, boolean isItem) {
        return new CustomermGroupViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_customer_group, parent, false), isItem);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position, boolean isItem) {
        CustomermGroupViewHolder viewHolder = (CustomermGroupViewHolder) holder;
        CustomerGroupItem groupItem = getItem(position);
        viewHolder.tvGroupName.setText(groupItem.getGroupName());
        viewHolder.rlGroupAddressAndArrow.setVisibility(View.VISIBLE);
        viewHolder.tvGroupNo.setText(TextUtils.isEmpty(groupItem.getNum()) ? "" : groupItem.getNum() + "位");
/*        if (CUSTOMER_INFO_ACTIVITY.equals(mAction)){
            viewHolder.rlGroupAddressAndArrow.setVisibility(View.VISIBLE);
            viewHolder.tvGroupNo.setText(TextUtils.isEmpty(groupItem.getNum()) ? "" : groupItem.getNum() + "位");
        }else {
            viewHolder.rlGroupAddressAndArrow.setVisibility(View.GONE);
        }*/

    }

    @Override
    public int getSwipeLayoutResourceId(int i) {
        return 0;
    }

    class CustomermGroupViewHolder extends RecyclerViewHolder {
        TextView tvGroupName;
        TextView tvGroupNo;
        LinearLayout llGroup;
        RelativeLayout rlGroupAddressAndArrow;

        public CustomermGroupViewHolder(View itemView, boolean isItem) {
            super(itemView, isItem);
            tvGroupName = (TextView) itemView.findViewById(R.id.item_tv_group_name);
            tvGroupNo = (TextView) itemView.findViewById(R.id.item_tv_group_no);
            llGroup = (LinearLayout) itemView.findViewById(R.id.item_ll_group);
            rlGroupAddressAndArrow = (RelativeLayout) itemView.findViewById(R.id.item_rl_group);
            itemView.setOnClickListener(null);
            llGroup.setOnClickListener(this);
        }
    }
}
